package com.ysw.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName KafkaController
 * @Description TODO
 * @Author ysw
 * @Date 2021/12/12 17:16
 */
@RestController
@RequestMapping("/msg")
@SuppressWarnings("all")
public class KafkaController {

    private final static String TOPIC = "my-topic1";

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @RequestMapping("/send")
    public String sendMsg() {
        kafkaTemplate.send(TOPIC, 0, "key", "this is a message");
        return "success";
    }
}